//
// Created by liushuai on 2021/2/22.
//

#include "getMinimumDifference.h"
using namespace std;
void midTraval(TreeNode* root, int& pre, int& res) {
  if (!root) return;
  midTraval(root->left, pre, res);
  if (pre == -1) {
    pre = root->val;
  } else {
    int temp = root->val - pre < 0 ? pre - root->val : root->val - pre;
    pre = root->val;
    res = res < temp ? res : temp;
  }
  midTraval(root->right, pre, res);
}
int getMinimumDifference(TreeNode* root) {
  int pre = -1;
  int res = INT_MAX;
  midTraval(root, pre, res);
  return res;
}